package com.kzw.oa.blog;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 复制图片自动上传，设置项目部署
 * */
import com.kzw.oa.blog.model.Article;

public class UEditorUtil {

	public static void replaceUploadUrl(Article article) {

		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest();
		String baseUrl = request.getContextPath();

		// 将相对路径改成绝对路径：src="/ueditor/ ==> src="path/ueditor/
		String content = article.getContent().replace("src=\"/ueditor/", "src=\"" + baseUrl + "/ueditor/");
		article.setContent(content);
	}

}
